<ul id="roleauthtree" class="tree"></ul>

<script type="text/javascript">
var nodeinfo = null;	
var	nodetype = -1;	//节点类型:0当前操作的是静态节点; 1是扩展节点; -1是未选择任何节点
var nodename = new Array(); //当操作静态权限时有用,把每勾一项的节点名保存,显示在 tip.auth
var findIds = function(){
    	var treeids='' ;
    	var i =0;
    	var m = document.getElementsByName('auth_ids'); 
   	 	var l = m.length;
        for ( var j=0; j< l; j++)
        {
            if(m[j].checked){
            	if(treeids!='') 
            		treeids += ',' + m[j].value;
            	else
            	 	treeids = m[j].value;
            } 
        }
		return treeids;
    }
    
var cancelIds = function(){
	var m = document.getElementsByName('auth_ids'); 
 	var l = m.length;
    for ( var j=0; j< l; j++)
    {
    m[j].checked = false;
    }
}

//下面LIST的获取写在这里而不是  role.auth.setter.html 原因:
//当点击树节点(扩展权限)时要调用loadAuthdynanodeList,这里无法调用role.auth.setter.html的方法.
//但是可以把这个结果加到role.auth.setter.html的DIV中.
var dynanodeset=null;
var dynanodeset_pageno = 1;
if (dynanodeset) { dynanodeset_pageno = dynanodeset.findCurrentPage(); }

var loadAuthdynanodeList = function(){

	var columns = [{text:'扩展权限',name:'pcol'},{text:'扩展说明',name:'vcol'}];//要显示的字段
	var dataURLParams = {"scid":"authnodedyna", "authid":nodeinfo.id};
	if (!dynanodeset){
		dynanodeset = new MUI.List({
			instanceName: 'dynanodeset',
	       	container:'div.authdyna.auth',
	       	showCheckBox:true,
			showCommand:false,
	       	id: "adynanodesetList",
	       	columns:columns,
	       	dataURL:dataURL,
	       	dataURLParams: dataURLParams,
	       	cbName: 'idsdynanodeset',
	       	saveCheck:true,
	       	commands:[]
	   	});//MUI.List
   	}
   	dynanodeset.setDataURLParams(dataURLParams);
   	dynanodeset_pageno = 1;
   	dynanodeset.findList(dynanodeset_pageno);
}

var onNodeClick = function(bean){
	nodeinfo = bean;
	if( 1 == nodeinfo.kind ){
		$('tip.auth').set('html','正在为添加<font color=red>扩展权限('+ nodeinfo.title + ')</font>');
		//刷新扩展权限对应内容(这里只刷新div.authdyna.auth)
		loadAuthdynanodeList();
		//清除静态权限勾选的CHECKBOX
		cancelIds();
		nodename.empty();
		nodetype = 1;
	}
}
 
var changeNodeUI = function(element,bean){
	if(0==bean.kind){
		var node = new Element("input", {"type":"checkbox","id":"auth_ids","name":"auth_ids","value":bean.id});
		node.addEvent("click", function (e) {
		//只有静态权限才有CHECKBOX,点击后,去掉显示扩展权限表的内容
			$('div.authdyna.auth').set('html','');
			if(''!=findIds()){
				if(nodename.contains(bean.title)) 
					nodename.erase(bean.title);
				else
					nodename.include(bean.title);	 
				$('tip.auth').set('html','正在为添加<font color=red>静态权限(' + nodename +')</font>');
				nodetype = 0;
			}else{
				$('tip.auth').set('html','<font color=red>必须选择权限树节点</font>');
				nodetype = -1;
				nodename.empty();
			}
		});
		element.grab((document.createTextNode(' ')),'top');
		element.grab(node,'top');
	}
}
 

///////////////////////////////////////////////////////////////////////////////////////

var dataURL = '/data/sc.action';
var dataURLParams = {"scid":"authtree_1"};
var event = {"onNodeClick":'onNodeClick', "onAddElement":'changeNodeUI'};

new MUI.Require({
		css: [MUI.path.plugins + 'tree/css/style.css'],
		js: [MUI.path.plugins + 'tree/scripts/tree.js'],
		onload: function(){
			loadTree('roleauthtree', dataURL, dataURLParams, event);
		}	
});
 
</script>
